//
//  PracyAuthor.swift
//  Edaixi-iOS
//
//  Created by 刘树华 on 2017/12/1.
//  Copyright © 2017年 刘树华. All rights reserved.
//

import Foundation
import AVFoundation
import Photos
import CoreLocation
func checkCameraAuthorization(completionHandler: @escaping (_ authorized:Bool)->() )  {
    switch AVCaptureDevice.authorizationStatus(for: AVMediaType.video) {
    case .authorized:
        completionHandler(true)
    case .notDetermined :
        AVCaptureDevice.requestAccess(for: AVMediaType.video, completionHandler: completionHandler)
    case .denied :
        completionHandler(false)
    case .restricted :
        completionHandler(false)
   
    }
}

func checkPhotoLibraryAuthorization(_ completionHandler: @escaping ((_ authorized: Bool) -> Void)){
    switch PHPhotoLibrary.authorizationStatus() {
    case .authorized:
        completionHandler(true)
    case .notDetermined :
        PHPhotoLibrary.requestAuthorization({ (status) in
            completionHandler(status == PHAuthorizationStatus.authorized)
        })
    case .denied :
        completionHandler(false)
        
    default:
        
        completionHandler(false)
    }
}

func checkRecordPermission(_ completionHandler: @escaping ((_ authorized: Bool) -> Void))  {
    switch AVAudioSession.sharedInstance().recordPermission() {
    case .denied:
        completionHandler(false)
    case.granted:
        completionHandler(true)
    case.undetermined:
        AVAudioSession.sharedInstance().requestRecordPermission({ (finished) in
            completionHandler(finished)
        })
   
    }
}

